package com.sun.demo;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.sun.BmobDemo.R;
import com.sun.BmobDemo.UserAccount;

import java.util.List;

/**
 * Created by Thinkpad on 2016/3/8.
 */
public class Dreg extends Bmob {
    private TextView textView4;
    private TextView textViewExit;
    private EditText edittextPhone;
    private Button buttonSendSms;
    private EditText editTextCheckNum;
    private EditText editTextUserName;
    private EditText editTextPwd;
    private EditText editTextConfirmingPwd;
    private Button buttonReg;
    private CheckBox checkBoxReg;
    private TextView textViewTerms;




    private void assignViews() {
        textView4 = (TextView) findViewById(R.id.textView4);
        textViewExit = (TextView) findViewById(R.id.textView_exit);
        edittextPhone = (EditText) findViewById(R.id.edittext_phone);
        buttonSendSms = (Button) findViewById(R.id.button_sendSms);
        editTextCheckNum = (EditText) findViewById(R.id.editText_checkNum);
        editTextUserName = (EditText) findViewById(R.id.editText_UserName);
        editTextPwd = (EditText) findViewById(R.id.editText_Pwd);
        editTextConfirmingPwd = (EditText) findViewById(R.id.editText_confirmingPwd);
        buttonReg = (Button) findViewById(R.id.button_reg);
        checkBoxReg = (CheckBox) findViewById(R.id.checkBox_reg);
        textViewTerms = (TextView) findViewById(R.id.textView_terms);
        edittextPhone.setText("13624267104");
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.reg_activity);
        assignViews();
        initBmob(this, "784b5674076d5c684fe1a76f2042409c");

        buttonReg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String checknum = editTextCheckNum.getText().toString();
                String name = editTextUserName.getText().toString();
                String phone = edittextPhone.getText().toString();
                checkSmsNum(phone,checknum);
                updateBmobInstallation(name);
                sendMsg(name,"li",phone);

            }
        });
        buttonSendSms.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name = editTextUserName.getText().toString();
                String phone = edittextPhone.getText().toString();
                UserAccount user = new UserAccount();
                user.setName(name);
                user.setPhoneNum(phone);
                pushMsgAll(phone);
//                sendSMSCheckedNum(phone,"sms");
//                updataUserAccount(user);
//                addUserAccount(user);
//                queryAll();
            }
        });

    }

    @Override
    public void returnUser(List<UserAccount> account) {
        for(UserAccount b:account) {
            Log.i("1", b.toString()+"\n");
        }
    }
}
